package com.hzit.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzit.entity.Student;
import com.hzit.service.StudentService;
import com.hzit.mapper.StudentMapper;
import com.hzit.utils.PageResult;
import com.hzit.utils.R;
import com.hzit.vo.StudentVO;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
    implements StudentService{

    @Override
    public PageResult<Student> search(Integer page, Integer pageSize, StudentVO studentVO) {
        QueryWrapper<Student> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(studentVO.getSname()),"sname",studentVO.getSname())
                .like(StrUtil.isNotBlank(studentVO.getAddr()),"addr",studentVO.getAddr())
                .eq(studentVO.getCid()!=null && studentVO.getCid()!=0,"cid",studentVO.getCid());
        Page<Student> studentPage = this.baseMapper.selectPage(new Page<>(page, pageSize), queryWrapper);
        return new PageResult<>(studentPage.getTotal(),studentPage.getRecords());
    }
}




